package com.zhanglong.kotlinfish.Util.System

import android.content.Context
import android.content.pm.PackageManager

class VersionUtil {
    companion object {
        //获取软件版本号，对应AndroidManifest.xml下android:versionCode
        fun versionCode(context: Context): Int {
            var versionCode = 0
            try {
                versionCode = context.packageManager.getPackageInfo(context.packageName, 0).versionCode
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }

            return versionCode
        }
        // 获取版本号名称V
        fun versionName(context: Context): String {
            var verName = "V1.0.0"
            try {
                verName = context.packageManager.getPackageInfo(context.packageName, 0).versionName
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }

            return "V$verName"
        }
    }
}